<?php
echo date("北京时间:Y年m月d日 H:i:s.v e\n");
$d=new DateTime();//创建一个日期对象，默认值"now"表示当前的日期时间
$d=new DateTime("2000-10");//2000-10-01 00:00:00.0000000
$d=new DateTime("2000-10-5");//2000-10-05 00:00:00.0000000
$d=new DateTime("2000-10 12:34:56");//2000-10-05 12:34:56.0000000
$d=new DateTime("2000-10 12:34");//2000-10-01 12:34:00.0000000
$d=new DateTime("12:34");//今天日期的 2000-10-29 12:34:00.0000000
$d=new DateTime("20001005 123456");//2000-10-05 12:34:56.0000000
$d=new DateTime("2000/10/1 12:34:56");//2000-10-01 12:34:56.0000000
echo $d->format("北京时间:Y年m月d日 H:i:s.v e\n");//2000-10-01 12:34:56.000 Asia/shanghai
echo $d->format("年:Y\n");//年：2000
$a=['name'=>'zs', 'age'=>18];
//获取时间戳，从UTC 1970-1-1 0时到现在的秒数
$d=new DateTime("1970-1-1 8:0".new DateTimeZone('Asia/Shanghai'));
echo "UNIX时间戳：",$d->getTimestamp(),"\n";
//根据时间戳创建日期，注意时间戳前面一点要加@
echo (new DateTime("@1761723189"))->format("Y-m-d h:i:s.v e\n");//2025-10-29 07:33:09.000
//设置时区，可以看见北京时间对应的不同地区的时间
$d=new DateTime();
echo $d->format("Y-m-d H:i:s.v e\n");//2025-10-29 15:50:18.551 Asia/Shanghai
$d->setTimezone(new DateTimeZone("UTC"));
echo $d->format("Y-m-d H:i:s.v e\n");//2025-10-29 07:50:18.551 UTC
//DateTime可变的， datetimeimmutable不可变
$d=new DateTime("2025-10-29 12:34:56");
echo $d->format("北京时间：Y-m-d H:i:s.v e\n");
echo $d->modify("+1 day")->format("Y-m-d H:i:s.v e\n");
echo $d->modify("-2 day")->format("Y-m-d H:i:s.v e\n");
echo $d->setDate(2000,10,1)->format("Y-m-d H:i:s.v e\n");
echo $d->modify("2000-10")->format("Y-m-d H:i:s.v e\n");
echo $d->setTime(23,45,)->format("Y-m-d H:i:s.v e\n");
echo $d->modify("23:45")->format("Y-m-d H:i:s.v e\n");
//计算本周、上周、下周一的日期
echo $d->modify("monday this week")->format("Y-m-d H:i:s.v e\n");
echo $d->modify("monday last week")->format("Y-m-d H:i:s.v e\n");
echo $d->modify("monday next week")->format("Y-m-d H:i:s.v e\n");
//当前是第九周，求开学日期
$currentweek=9;
echo (new DateTime())
     ->modify("monday -$currentweek weeks + 8 hours")
     ->format("Y-m-d H:i:s.v e\n");
//当前月1号是星期几
echo (new DateTime("2025-10"))->format("N")-1,"\n";//星期一：0，星期日：6
//当前月有几天
echo (new DateTime("2025-10"))->format("t"),"\n";

//编写函数，根据给定年，月，显示阅历
